// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2009-10-26 21:57:27


// Source File Name:   LocalVariableTable.java

package com.vhly.classfile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

// Referenced classes of package com.vhly.classfile:
//            LocalVariable, Attribute

public class LocalVariableTable
        implements Attribute {

    private int name_index;
    private int data_len;
    private int lvt_count;
    private Vector lvts;

    public LocalVariableTable() {
        name_index = 0;
        data_len = 0;
        lvt_count = 0;
        lvts = new Vector();
    }

    public void setNameIndex(int i) {
        name_index = i;
    }

    public int getNameIndex() {
        return name_index;
    }

    public void setDataLen(int i) {
        data_len = i;
    }

    public int getDataLen() {
        return data_len;
    }

    public LocalVariable getLVAt(int index) {
        lvt_count = lvts.size();
        if (index < 0)
            return null;
        if (index >= lvt_count)
            return null;
        else
            return (LocalVariable) (LocalVariable) lvts.elementAt(index);
    }

    public Enumeration getLVs() {
        return lvts.elements();
    }

    public int size() {
        lvt_count = lvts.size();
        return lvt_count;
    }

    public void read(DataInputStream datainputstream, boolean flag)
            throws IOException {
        if (flag)
            name_index = datainputstream.readUnsignedShort();
        data_len = datainputstream.readInt();
        lvt_count = datainputstream.readUnsignedShort();
        for (int i = 0; i < lvt_count; i++) {
            LocalVariable localvariable = new LocalVariable();
            localvariable.read(datainputstream);
            lvts.add(localvariable);
        }

    }

    public void write(DataOutputStream dataoutputstream)
            throws IOException {
        dataoutputstream.writeShort(name_index);
        dataoutputstream.writeInt(data_len);
        dataoutputstream.writeShort(lvt_count);
        for (int i = 0; i < lvt_count; i++) {
            LocalVariable localvariable = (LocalVariable) lvts.elementAt(i);
            localvariable.write(dataoutputstream);
        }

    }

    public int getType() {
        return 5;
    }
}